require "public"
local MJLogic = require "common/MJLogic"

local table_insert = table.insert
local table_remove = table.remove

local puke_player = class("puke_player")

function puke_player:ctor()
    self.total_score = 0 
    self.bank_continue_num = 0 
	self.is_ready_ = false
	self.is_out_line_ = false	 
	self.score_stat = {}
	self:reset_game()
	self.latitude = 0 
	self.longitude = 0 
	self.gps_type = 0 
end
 
function puke_player:reset_game()
    self.hand_ = {} 
    self.new_hand = {} 
	self.card_type = ''
	self.card_color = 0
	self.card_value = 0
	self.score_ = 0
	self.fan	= 0   
	self.odds	= 0  
	self.bank_odds	= -1  
	self.kai_pai	= 0  
end


function puke_player:set_gps(latitude,longitude,type)
	self.latitude = latitude
	self.longitude = longitude
	self.gps_type = type
end
function puke_player:get_gps()
	return self.latitude,self.longitude,self.gps_type
end
 
local function rad(d) 
    local rs = d * math.pi / 180.0
    return rs
end


 
local function transformLat(x,y) 
    local ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * math.sqrt(math.abs(x))
    ret = ret + (20.0 * math.sin(6.0 * x * math.pi) + 20.0 * math.sin(2.0 * x * math.pi)) * 2.0 / 3.0
    ret = ret + (20.0 * math.sin(y * math.pi) + 40.0 * math.sin(y / 3.0 * math.pi)) * 2.0 / 3.0
    ret = ret + (160.0 * math.sin(y / 12.0 * math.pi) + 320 * math.sin(y * math.pi / 30.0)) * 2.0 / 3.0
    return ret
end

local function transformLon(x, y)
    local ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * math.sqrt(math.abs(x))
    ret = ret + (20.0 * math.sin(6.0 * x * math.pi) + 20.0 * math.sin(2.0 * x * math.pi)) * 2.0 / 3.0
    ret = ret + (20.0 * math.sin(x * math.pi) + 40.0 * math.sin(x / 3.0 * math.pi)) * 2.0 / 3.0
    ret = ret + (150.0 * math.sin(x / 12.0 * math.pi) + 300.0 * math.sin(x / 30.0 * math.pi)) * 2.0 / 3.0
    return ret
end

local function delta(lat, lon)  
    local a = 6378245.0
    local ee = 0.00669342162296594323
    local dLat = transformLat(lon - 105.0, lat - 35.0)
    local dLon = transformLon(lon - 105.0, lat - 35.0)
    local radLat = lat / 180.0 * math.pi
    local magic = math.sin(radLat)
    magic = 1 - ee * magic * magic
    local sqrtMagic = math.sqrt(magic)
    dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * math.pi)
    dLon = (dLon * 180.0) / (a / sqrtMagic * math.cos(radLat) * math.pi)
    return dLat,dLon
end

function puke_player:WGStoGCJ(wgsLat,wgsLon)
    local dLat,dLon = delta(wgsLat, wgsLon)
    wgsLat = wgsLat + dLat
    wgsLon = wgsLon + dLon
    return wgsLat,wgsLon
end

function puke_player:getDistance(lat1,lng1,lat2,lng2)
	local radLat1 = rad(lat1)
	local radLat2 = rad(lat2)
	local a = radLat1 - radLat2
	local b = rad(lng1) - rad(lng2)
	local aa = math.sin(a/2)
	local bb = math.sin(b/2)
	local s = 2 * math.asin(math.sqrt( aa * aa + 
	math.cos(radLat1)*math.cos(radLat2)* bb * bb))
	s = math.floor(s * 6378137.0) -- 单位米 6378137  
	return s
end

function puke_player:set_kai_pai(tag)
	self.kai_pai = tag
end

function puke_player:get_kai_pai()
	return self.kai_pai
end
function puke_player:set_bank_continue_num(tag)
	self.bank_continue_num = tag
end

function puke_player:get_bank_continue_num()
	return self.bank_continue_num
end
function puke_player:set_odds(tag)
	self.odds = tag
end

function puke_player:get_odds()
	return self.odds
end

function puke_player:set_bank_odds(tag)
	self.bank_odds = tag
end

function puke_player:get_bank_odds()
	return self.bank_odds
end

function puke_player:set_out_line(flag)
	self.is_out_line_ = flag
end

function puke_player:is_out_line()
	return self.is_out_line_
end
 
 

function puke_player:set_jiesan_time()
	self.last_jiesan_time = os.time()
end

function puke_player:get_jiesan_time()
	return self.last_jiesan_time
end

function puke_player:set_ready(flag)
    self.is_ready_ = flag
end
 

function puke_player:is_ready()
    return self.is_ready_
end

function puke_player:set_stat(i,score)
	self.score_stat[i] = score
end

function puke_player:get_stat()
	return self.score_stat
end
   
-- 手牌类型
function puke_player:set_card_type(type)
    self.card_type = type
end

function puke_player:get_card_type()
    return self.card_type
end
  
-- 手牌大小
function puke_player:set_card_value(value)
    self.card_value = value
end

function puke_player:get_card_value()
    return self.card_value
end
-- 手牌颜色
function puke_player:set_card_color(value)
    self.card_color = value
end

function puke_player:get_card_color()
    return self.card_color
end

--增加分数
function puke_player:up_score(num)
	self.score_ =  num
	self.total_score = self.total_score + num
	return self.score_,self.total_score
end
 

function puke_player:set_score(tag)
    self.score_ = tag
end

function puke_player:get_score()
    return self.score_
end

function puke_player:add_total_score(tag)
    self.total_score = self.total_score + math.abs(tag)
end

function puke_player:decr_total_score(tag)
    self.total_score = self.total_score - math.abs(tag)
end

function puke_player:get_total_score()
    return self.total_score
end


function puke_player:get_new_hand()
    return self.new_hand
end
function puke_player:set_new_hand(asdf)
    self.new_hand = asdf
end

function puke_player:get_hand()
    return self.hand_
end
function puke_player:clear_hand()
    self.hand_ = {}
end
  
function puke_player:insert_hand_card( tbl )
    for k,v in ipairs(tbl) do
        table_insert(self.hand_,v)
    end
end

return puke_player
